local skel = fk.CreateSkill{
    name = "wm__cangbi",
    tags = { Skill.Compulsory },
}
local U = require "packages/utility/utility"


Fk:loadTranslationTable{
    ["wm__cangbi"] = "藏壁",
    [":wm__cangbi"] = [[锁定技，每回合首次受到伤害后，回复1点体力。回合开始时，若你未受伤，你跳过出牌阶段和弃牌阶段。若你未受伤，其他角色于出牌阶段使用的首张【杀】和首张普通锦囊牌对你无效。]],
}

skel:addEffect(fk.Damaged, {
    anim_type = "defensive",
    can_trigger = function(self, event, target, player, data)
        if target == player and player:hasSkill(skel.name) then
            local damage_events = player.room.logic:getActualDamageEvents(1, function (e)
                return e.data.to == player
            end, Player.HistoryTurn)
            if damage_events[1].data == data then
                return player:isWounded()
            end
        end
    end,
    on_use = function(self, event, target, player, data)
        local room = player.room
        room:recover{
            who = player,
            num = 1,
            recoverBy = player,
            skillName = skel.name,
        }
    end,
})

skel:addEffect(fk.TurnStart, {
    can_trigger = function (self, event, target, player, data)
        if target == player and player:hasSkill(skel.name) then
            return not player:isWounded()
        end
    end,
    on_use = function (self, event, target, player, data)
        local room = player.room
        player:skip(Player.Play)
        player:skip(Player.Discard)
    end,
})

skel:addEffect(fk.CardUsing, {
    anim_type = "control",
    max_phase_use_time = 1,
    can_trigger = function(self, event, target, player, data)
        if player:hasSkill(skel.name) and target ~= player and target.phase == Player.Play and data.card:isCommonTrick() then
            local use_events = player.room.logic:getEventsOfScope(GameEvent.UseCard, 1, function (e)
                return e.data.from == target and e.data.card:isCommonTrick()
            end, Player.HistoryTurn)
            return use_events[1].data == data and data:hasTarget(player)
        end
    end,
    on_cost = function (self, event, target, player, data)
        event:setCostData(self, {tos = {target}})
        return true
    end,
    on_use = function(self, event, target, player, data)
        data.nullifiedTargets = data.nullifiedTargets or {}
        table.insertTableIfNeed(data.nullifiedTargets, player)
    end,
})

skel:addEffect(fk.CardUsing, {
    anim_type = "control",
    max_phase_use_time = 1,
    can_trigger = function(self, event, target, player, data)
        if player:hasSkill(skel.name) and target ~= player and target.phase == Player.Play and data.card.trueName == "slash" then
            local use_events = player.room.logic:getEventsOfScope(GameEvent.UseCard, 1, function (e)
                return e.data.from == target and e.data.card.trueName == "slash"
            end, Player.HistoryTurn)
            return use_events[1].data == data and data:hasTarget(player)
        end
    end,
    on_cost = function (self, event, target, player, data)
        event:setCostData(self, {tos = {target}})
        return true
    end,
    on_use = function(self, event, target, player, data)
        data.nullifiedTargets = data.nullifiedTargets or {}
        table.insertTableIfNeed(data.nullifiedTargets, player)
    end,
})

return skel